package com.swak.leader;

/**
 * Leader.
 * 
 * @author 618lf
 */
public interface Leader {

	/**
	 * 返回是否是Leader.
	 * 
	 * @return
	 */
	boolean isMe();

	/**
	 * 加入竞选
	 */
	void join() throws Exception;

	/**
	 * 退出竞选
	 */
	void leave() throws Exception;

	/**
	 * 添加监听器
	 * 
	 * @param listener
	 */
	void addListener(ChangeListener listener);

	/**
	 * 唯一的一个
	 */
	Leader Single = new SingleLeader();

	/**
	 * 单机系统中唯一一个
	 * 
	 * @author 618lf
	 */
	public static class SingleLeader implements Leader {

		@Override
		public boolean isMe() {
			return true;
		}

		@Override
		public void join() throws Exception {

		}

		@Override
		public void leave() throws Exception {

		}

		@Override
		public void addListener(ChangeListener listener) {

		}
	}
}
